package com.tr.rentcar.controller.home;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.model.bean.Discount;
import com.tr.rentcar.model.bean.User;
import com.tr.rentcar.model.bean.UserDiscount;
import com.tr.rentcar.model.dao.DiscountDao;
import com.tr.rentcar.model.dao.UserDiscountDao;

/**
 * Servlet implementation class HuoDong
 * 进入活动页面
 */
@WebServlet("/huodong")
public class ActiveController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	UserDiscountDao udd = new UserDiscountDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			DiscountDao ud = new DiscountDao();
			List<Discount> list = ud.findAll();
			request.setAttribute("list", list);
			//获取登录用户的id
			User user = (User) request.getSession().getAttribute("userinfo");
			if(user!=null){
				Integer uid=user.getUid();
				List<UserDiscount> udlist=udd.findById(uid);
				request.setAttribute("udlist", udlist);
				if (udlist.isEmpty()) {
					request.setAttribute("udlist", null);
				}
			}else{
				request.setAttribute("udlist", null);
			}
			// System.out.println(list);
			request.getRequestDispatcher("WEB-INF/jsp/active.jsp").forward(request, response);

		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
